/*
 *  Copyright 2005 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.webapp.util.questionnaire;

import java.util.Map;
import java.util.HashMap;

/**
 * <p>Webapp constants for questionnaire module.</p>
 * <p/>
 * <p><a href="QuestionnaireModuleWebConstants.java.html"><i>View source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.4 $ $Date: 2006/06/28 16:23:14 $
 */
public class QuestionnaireModuleWebConstants {
	/**
	 * Context key under which ID of questionnaire is saved
	 */
	public static final String QUESTIONNAIRE_ID_KEY = "com.blandware.atleap.news.QUESTIONNAIRE_ID";

	/**
	 * Context key under which ID of question is saved
	 */
	public static final String QUESTION_ID_KEY = "com.blandware.atleap.news.QUESTION_ID";

	/**
	 * Context key under which ID of answer option is saved
	 */
	public static final String ANSWER_OPTION_ID_KEY = "com.blandware.atleap.news.ANSWER_OPTION_ID";

	/**
	 * Context key under which ID of filled questionnaire is saved
	 */
	public static final String FILLED_QUESTIONNAIRE_ID_KEY = "com.blandware.atleap.news.FILLED_QUESTIONNAIRE_ID";

	/**
	 * Name of questionnaires grid
	 */
	public static final String QUESTIONNAIRES_GRID = "questionnairesGrid";

	/**
	 * Name grid containing questionnaires which are available to fill
	 */
	public static final String QUESTIONNAIRES_TO_FILL_GRID = "questionnairesToFillGrid";

	/**
	 * Context key, under which collection of questionnaires is saved
	 */
	public static final String QUESTIONNAIRES_COLLECTION_KEY = "com.blandware.atleap.news.QUESTIONNAIRES_COLLECTION";

	/**
	 * UrlRewrite filter prefix for questionnaires
	 */
	public static final String QUESTIONNAIRE_URI_PREFIX = "/rw/questionnaire";

	/**
	 * Context key under which merged annotation of questionnaire is stored
	 */
	public static final String QUESTIONNAIRE_MERGED_ANNOTATION_KEY = "com.blandware.atleap.QUESTIONNAIRE_MERGED_ANNOTATION";

	/**
	 * Context key which prevents double form submit (instead of transactions)
	 */
	public static final String QUESTIONNAIRE_SUBMITTED_ACTION_KEY = "com.blandware.atleap.QUESTIONNAIRE_SUBMITTED_ACTION_KEY";

	/**
	 * Context key which prevents double form submit (instead of transactions).
     * This is used for questionnaire filling
	 */
	public static final String FILL_QUESTIONNAIRE_SUBMITTED_ACTION_KEY = "com.blandware.atleap.FILL_QUESTIONNAIRE_SUBMITTED_ACTION_KEY";

    /**
     * Context key under which map of chosen locales for annotation is stored
     */
    public static final String QUESTIONNAIRE_CHOSEN_ANNOTATIONS_KEY = "com.blandware.atleap.QUESTIONNAIRE_CHOSEN_ANNOTATIONS";

	/**
	 * Context key under which merged title of question is stored
	 */
	public static final String QUESTION_MERGED_TITLE_KEY = "com.blandware.atleap.QUESTION_MERGED_TITLE";

	/**
	 * Context key which prevents double form submit (instead of transactions)
	 */
	public static final String QUESTION_SUBMITTED_ACTION_KEY = "com.blandware.atleap.QUESTION_SUBMITTED_ACTION_KEY";

    /**
     * Context key under which map of chosen locales for title is stored
     */
    public static final String QUESTION_CHOSEN_TITLES_KEY = "com.blandware.atleap.QUESTIONNAIRE_CHOSEN_TITLES";

    /**
     * ID of option which means 'nothing selected'
     */
    public static final int NOTHING_SELECTED_OPTION_ID = -1;

    /**
     * String that serves as a boundary between question ID and answer ID in
     * checkbox ID
     */
    public static final String CHECKBOX_ID_DELIMITER = "_";

    /**
     * Maps regexes identifiers (which serve as parts of message keys) to
     * regexps themselves
     */
    public static Map VALIDATION_REGEXES = null;

    /**
     * Prefix for keys which contain messages for built-on validation regexes
     */
    public static final String REGEX_IDENTIFIER_KEY_PREFIX = "questionnaire.question.form.regex.";

    static {
        String specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
        String validChars = "[^\\s" + specialChars + "]";
        String atom = validChars + "+";
        String quotedUser = "(\"[^\"]*\")";
        String word = "(" + atom + "|" + quotedUser + ")";
        String user = word + "(\\." + word + ")*";
        String ip = "(\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})[.](\\d{1,3})";
        String symbolic = atom + "(\\." + atom + ")*";
        String domain = "(" + ip + "|" + symbolic + ")";

        VALIDATION_REGEXES = new HashMap();
        VALIDATION_REGEXES.put("integer", "^\\d+$");
        VALIDATION_REGEXES.put("float", "^(\\d+)\\.(\\d+)$");
        VALIDATION_REGEXES.put("email", "^(" + user + ")@(" + domain + ")$");
        VALIDATION_REGEXES.put("httpUrl", "^(https?:\\/\\/)?([a-zA-Z0-9\\.\\-_]+)(:(\\d+))?(\\/[^?]*)?(\\?(.*))?$");
    }
}
